package com.example.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.myapplication.Fragment.HotAlbumsFragment;
import com.example.myapplication.Fragment.HotMVFragment;
import com.example.myapplication.Fragment.HotSongFragment;
import com.example.myapplication.Fragment.SongDescFragment;
import com.example.myapplication.R;
import com.example.myapplication.adapter.viewPagerAdapter.SingerDetailAdapter;
import com.example.myapplication.entity.Artist;
import com.example.myapplication.tools.BarTransparent;
import com.example.myapplication.tools.SetColor;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class SingerDetailActivity extends AppCompatActivity {
    private ViewPager view_page;
    private TabLayout tab_Layout;
    private List<Fragment> fragmentList = new ArrayList<>();
    private ImageView img_singer;
    private MaterialToolbar toolbar;
    private Artist artist;
    private CollapsingToolbarLayout collapsing;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarTransparent.makeStatusBarTransparent(this);
        BarTransparent.setAndroidNativeLightStatusBar(this,true);
        setContentView(R.layout.activity_singer_detail);
        view_page = findViewById(R.id.recyclerView1);
        tab_Layout = findViewById(R.id.tab_layout);
        img_singer = findViewById(R.id.img_singer);
        toolbar = findViewById(R.id.toolbar);
        collapsing = findViewById(R.id.main_collapsing);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        artist = (Artist)bundle.getSerializable("singer");
        toolbar.setTitle(artist.getName());
        SetColor.asBitmap(artist.getImg1v1Url(),this,collapsing);

        Glide.with(this).load(artist.getImg1v1Url())
                .error(R.drawable.ic_baseline_refresh_24)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.ic_baseline_refresh_24)
                .centerCrop()
                .into(img_singer);



        fragmentList.add(new HotSongFragment().newInstance(bundle));
        fragmentList.add(new HotAlbumsFragment().newInstance(bundle));
        fragmentList.add(new HotMVFragment().newInstance(bundle));
        fragmentList.add(new SongDescFragment().newInstance(bundle));
        SingerDetailAdapter adapter = new SingerDetailAdapter(getSupportFragmentManager(),fragmentList);
        view_page.setAdapter(adapter);
        view_page.setOffscreenPageLimit(3);
        tab_Layout.setupWithViewPager(view_page);
    }
}